package com.anne.fish.dao.hibernate;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.anne.fish.dao.InfoImageDao;
import com.anne.fish.model.InfoImage;

@Repository("infoImageDao")
public class InfoImageDaoHibernate extends GenericDaoHibernate<InfoImage, Long> implements InfoImageDao {

    public InfoImageDaoHibernate() {
        super(InfoImage.class);
    }
    
    @SuppressWarnings("unchecked")
	public List<InfoImage> findByInfoId(Long infoId){
    	return this.getHibernateTemplate().find("from InfoImage where infoId =?", infoId);
    }
    
    public Integer upddateBatch(List<InfoImage> imgs){
    	Long infoId = imgs.get(0).getInfoId();
    	StringBuffer sb = new StringBuffer();
    	sb.append(" update InfoImage set infoId = ? where id in(");
    	for(int i=0;i<imgs.size();i++){
    		InfoImage img = imgs.get(i);
    		if(i!=imgs.size()-1){
    			sb.append(img.getId()).append(" , " );
    		}else{
    			sb.append(img.getId()).append(" ) " );
    		}
    	}
    	return this.updateOrDelete(sb.toString(), infoId);
    }
}
